const util = require('../../utils/util')
const app = getApp();
Page({
  data:{
    api: app.globalData.api,
    products: [],
    uid: '0',

  },
  onLoad(options) {
    this.data.uid=wx.getStorageSync("uid")
    util.http('/collectlist?uid='+this.data.uid, resp=>{
      this.data.products=resp
      console.log("收藏夹列表")
      console.log(resp)
      this.setData(this.data)
    })
  },
  onPullDownRefresh() { //下拉更新购物车列表
    util.http('/collectlist?uid='+this.data.uid, resp=>{
      this.data.products=resp
      this.setData(this.data)
    })
  },
  deleteHandler(e){
    var pid = e.currentTarget.dataset.pid
    console.log(pid)
    util.http('/cancelcollect?pid='+pid+'&uid='+this.data.uid, resp=>{
      this.onLoad()
      this.setData(this.data)
      util.stopPullSetData(this)
    })
    // util.http('/collectlist?uid='+this.data.uid, resp=>{
    //   this.data.products=resp
      
    // })
  },
  detail(e){
    var item = e.currentTarget.dataset.item
    //存到本地直到软件卸载
    wx.setStorageSync('商品信息', item)
    //打开新的小程序页面
    util.redirect('detail')
  }
})